package com.uhu.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * @author liujunjie
 * @description
 * @create 2023-06-01 16:52
 **/
@ApiModel("响应参数")
@Data
public class ResponseData<T> implements Serializable {
    @ApiModelProperty("响应码 0-success 500-error")
    private int code;
    @ApiModelProperty("响应消息")
    private String message;
    @ApiModelProperty("响应值")
    private T data;

    public ResponseData() {
        this.code = 0;
        this.message = "success";
    }

    public static ResponseData ok(Object obj) {
        ResponseData responseData = new ResponseData();
        responseData.setData(obj);
        return responseData;
    }

    public static ResponseData ok() {
        ResponseData responseData = new ResponseData();
        responseData.setMessage("success");
        return responseData;
    }

    public static ResponseData error() {
        return error(500, "error");
    }

    public static ResponseData error(String message) {
        return error(500, message);
    }

    public static ResponseData error(int code, String message) {
        ResponseData responseData = new ResponseData();
        responseData.setCode(code);
        responseData.setMessage(message);
        return responseData;
    }
}
